package com.imooc.girl.result;

/**
 * 返回结果处理类
 * @author Administrator
 * @date 2018-9-10
 */
public class ResultHandler {

  // Prevents instantiation
  private ResultHandler() {
    throw new AssertionError();
  }

  /**
   * 操作成功
   * @return
   */
  public static Result<Object> success() {
    return success(null);
  }

  /**
   * 操作成功
   * @param object
   * @return
   */
  public static <E> Result<E> success(E object) {
    Result<E> result = new Result<E>();
    result.setErrorCode("0");
    result.setErrorMsg("OK");
    result.setData(object);
    return result;
  }

  /**
   * 操作成功
   * @param object
   * @return
   */
  public static <E> Result<E> successWithMsg(E object, String message) {
    Result<E> result = new Result<E>();
    result.setErrorCode("0");
    result.setErrorMsg(message);
    result.setData(object);
    return result;
  }

  /**
   * 操作失败
   * @param errorCode
   * @param errorMsg
   * @return
   */
  public static Result error(String errorCode, String errorMsg) {
    Result result = new Result();
    result.setErrorCode(errorCode);
    result.setErrorMsg(errorMsg);
    return result;
  }

  /**
   * 操作失败
   * @param enums
   * @return
   */
  public static Result error(ResultEnums enums) {
    Result result = new Result();
    result.setErrorCode(enums.getErrorCode());
    result.setErrorMsg(enums.getErrorMsg());
    return result;
  }

}
